package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.AddressService;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.utils.AuthContextUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.spzx.model.vo.address.addressVo;
import com.atguigu.spzx.model.dto.address.useraddressDto;

import java.util.List;

@Tag(name = "收获地址接口")
@RestController
@RequestMapping(value = "/address")
public class AdressController {

    @Autowired
    private AddressService addressService;

    @GetMapping("/getAddress")
    public Result<addressVo> getAddressById(){
        SysUser sysUser = AuthContextUtil.get();
        Long id = sysUser.getId();
        List<addressVo> address = addressService.GetAddressById(id);
        return Result.build(address, ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/deleteAddress/{id}")
    public Result deleteAddressById(@PathVariable Long id){
        addressService.deleteAddressById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/alterAddress")
    public Result alterAddressById(@RequestBody useraddressDto useraddressDto){
        addressService.alterAddressById(useraddressDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/saveAddress")
    public Result saveAddress(@RequestBody useraddressDto useraddressDto){
        addressService.saveAddress(useraddressDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}
